<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>质检入库-<!--{$voucher->voucherID}--></title>
    <style>
        .clf{clear:both;}
        .fll{float:left;}
        .scanForm{margin-left:15px;margin-top:30px;}
    </style>
</head>
<body>
<div style="width:100%">

    <!--{if $operFlg == 3 && $error_msg}-->

    <div class="comm-box">
        <!--{$error_msg}-->
    </div>

    <!--{else}-->

    <div class="items clearfix">
        <h2 style="" class="tal">正在操作：入库单质检入库-<!--{$voucher->voucherID}--></h2>
        <div class="items2">
        </div>
        <div style="background: #cccccc;width: 100%;height: 24px;line-height: 24px;">
            <div class="fll" style="margin-left: 20px;">入库单信息</div>
            <div style="float: right;margin-right: 20px;">
                状态：<span >
                    <!--{if $voucher->auditFlg == 0}-->
                        未审核
                    <!--{elseif $voucher->auditFlg == 1}-->
                        已审核
                    <!--{elseif $voucher->auditFlg == 2}-->
                        已作废
                    <!--{/if}-->
                </span>
            </div>
            <div style="float: right;margin-right: 20px;">
                总数量：<span id="totalAmount"><!--{$voucher->goodsAmount}--></span>件
            </div>
            <div style="float: right;margin-right: 30px;">
                总计：<span id="totalPrice"><!--{$voucher->goodsPrice}--></span>
            </div>
            <div style="float: right;margin-right: 40px;">
                所在仓库：<span id="storeName"><!--{$voucher->storeName}--></span>
            </div>
            <div class="clf"></div>
        </div>

        <!--{if $voucher->auditFlg == 2}-->
        <div style="width: 100%;margin-top: 10px;margin-bottom: 10px;">
            <table style="width: 100%;">
                <tr>
                    <td style="width: 70px;text-align: right;">作废原因：</td>
                    <td><!--{$voucher->remark}--></td>
                </tr>
            </table>
        </div>
        <!--{/if}-->

        
        <form id="goodsForm" name='goodsForm' method="post" onsubmit="return false;">
            <table id="goodsTable" class="table table-hover" style="width:100%;">
                <thead>
                    <tr class="active">
                        <th width="10%" style="text-align:center;font-weight:600">商品号</th>
                        <th width="30%" style="text-align:center;font-weight:600">商品名称</th>
                        <th width="10%" style="text-align:center;font-weight:600">商品规格</th>
                        <th width="10%" style="text-align:center;font-weight:600">商品进价(元)</th>
                        <th width="10%" style="text-align:center;font-weight:600">入库数量</th>
                        <th width="10%" style="text-align:center;font-weight:600">好货数量</th>
                        <th width="10%" style="text-align:center;font-weight:600">坏货数量</th>
                        <th width="10%" style="text-align:center;font-weight:600">拒收数量</th>
                    </tr>
                </thead>
            </table>
            <input type="hidden" name='voucherID' value="<!--{$voucherID}-->">
            <input type="hidden" name='flg' value="<!--{$flg}-->">
        </form>

    </div>
    <!--{/if}-->


    <div class="bottom_fixbox">
        <div class="rectbox tac">
            <input type="button" class="btn" onclick="audit.auditConfirm();" value="审核" />
            <input type="button" class="btn" onclick="E.closeWindows();" value="关闭" />
        </div>
    </div>



</div>

<script type="text/javascript">
    $("document").ready(function(){
        var voucherID = <!--{$voucher->voucherID}-->;
        jquery_ajax(7,{voucherID : voucherID},audit.callBack)
    })
    
    var audit = {
        callBack:function(response){
            if(response.code != 200){
                E.alert(response.message);
                return false;
            }
            //组织页面添加的html
            var dataLength = response.data.length;
            
            var html = "";
            for(var i=0;i<dataLength;i++){
                html +="<tr id='"+response.data[i].product_code+"'>";
                html +="<td align='center'>"+response.data[i].product_code+"</td>";
                html +="<td align='center'>"+response.data[i].goodsName+"</td>";
                html +="<td align='center'>"+response.data[i].goodsSpec+"</td>";
                html +="<td align='center'>"+response.data[i].goodsPrice+"</td>";
                html +="<td align='center'>"+response.data[i].goodsAmount+"</td>";
                html +="<td align='center'><input class='good_amount' name='goods_array["+response.data[i].goodsID+"][good_amount]' value='"+response.data[i].good_amount+"'/></td>";
                html +="<td align='center'><input class='bad_amount' name='goods_array["+response.data[i].goodsID+"][bad_amount]' value='"+response.data[i].bad_amount+"'/></td>";
                html +="<td align='center'><input class='rejection_amount' name='goods_array["+response.data[i].goodsID+"][rejection_amount]' value='"+response.data[i].rejection_amount+"'/></td>";
                html +="</tr>";
            }
            //插入页面
            $("#goodsTable").append(html);
        },
        auditConfirm:function(){
            var msg="";
            $("#goodsTable input").attr("style","");
            $("#goodsTable input").each(function(e){
                var inputName = $(this).attr("class");
                if($(this).val() == "" || !E.isInt($(this).val())){
                    $(this).attr("style","color:red");
                    msg = "好货数量、坏或数量及拒收数量不能为空且只能为正整数";
                }
            })
            if(msg){
                E.alert(msg);
                return false;
            }
           E.confirm("审核入库单会更新商品库存数量<br>您确认要审核该入库单吗？", "audit.audit");
        },
        audit:function(){
            var formData = E.getFormValues('goodsForm');
            E.loadding.open();
                E.ajax_get({
                    url: "/invokingAjax-backend/wms/putInStore.ajax?operFlg=5",
                    data:formData,
                    call: "audit.auditResult"
                });
        },
        auditResult:function(o){
            E.loadding.close();
            E.popup.close();
            if (o.code == 200) {
                E.opener("putInStore.load");
                E.alert(o.message, 2, "E.closeWindows");
            } else {
                if(o.product_code !=""){
                    $("#"+o.product_code+" input").attr("style","color:red");
                }
                E.alert(o.message);
            }
        }
    }
    function jquery_ajax(flg,data,func){
        $.ajax({
            type: "post",
            url: "/invokingAjax-backend/wms/putInStore.ajax?operFlg="+flg,
            dataType: "json",
            data: data,
            success: function( result_obj ) {
                func(result_obj);
            },
            error : function(msg){
                E.alert('网络不给力，请重新尝试...',1);
            }
        });
    }

</script>

</body>

</html>
